package com.beerq.view_manager;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.beerq.util.AppConfig;
import com.beerq.util.BasicHttp;
import com.beerq.util.Constants;

import okhttp3.RequestBody;

/**
 * 作者：minj on 2017/9/25 19:56
 * 登录和注册的一下后台服务请求的管理类
 */
public class RegisterAndLoginManager {

    /***
     * 获得验证码
     * @param context
     * @param phoneNo
     * @param callback
     * @return
     */
    public static boolean getValidateCode(Context context,String phoneNo,BasicHttp.IMyCallBack callback){
        RequestBody requestBodyPost=AppConfig.getBasicRequestBody(context).add("Args","{MobileNo:"+phoneNo+"}").build();
        return BasicHttp.postExec(context,Constants.server_domain+"MembershipCard/GetVerifyCode",requestBodyPost,callback);
    }

    /***
     * 注册接口
     * @param context
     * @param phoneNo 手机号
     * @param password 密码
     * @param WxNo 微信号
     * @param WxQr 微信二维码
     * @param HeadPic 头像URL
     * @param callback
     */
    public static void register(Context context,String phoneNo,String password,String WxNo,String WxQr,String HeadPic,BasicHttp.IMyCallBack callback){

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("Name",phoneNo);
        jsonObject.put("MobileNo",phoneNo);
        jsonObject.put("BrandId","1");
        jsonObject.put("PassWord",password);
        jsonObject.put("WxNo",WxNo);
        jsonObject.put("WxQr",WxQr);
        jsonObject.put("HeadPic",HeadPic);

        RequestBody requestBodyPost=AppConfig.getBasicRequestBody(context).add("Args",jsonObject.toJSONString()).build();
//

        BasicHttp.postExec(context,Constants.server_domain+"MembershipCard/Resiger",requestBodyPost,callback);

    }


    public static void bindPhoneAndWxNo(Context context,String phoneNo,String password,String WxNo,String name,String HeadPic,BasicHttp.IMyCallBack callback){

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("Name",name);
        jsonObject.put("MobileNo",phoneNo);
        jsonObject.put("PassWord",password);
        jsonObject.put("WxLoginId",WxNo);
        jsonObject.put("HeadPic",HeadPic);

        RequestBody requestBodyPost=AppConfig.getBasicRequestBody(context).add("Args",jsonObject.toJSONString()).build();
//

        BasicHttp.postExec(context,Constants.server_domain+"User/BindThirdParty",requestBodyPost,callback);

    }


    /***
     * 登录接口
     * @param context
     * @param phoneNo
     * @param password
     * @param callback
     */
    public static void login(Context context,String phoneNo,String password,BasicHttp.IMyCallBack callback){

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("UserCode",phoneNo);
        jsonObject.put("UserPwd",password);

        BasicHttp.getExec(context,Constants.server_domain+"User/Login?Args="+jsonObject.toJSONString()+"&Timestamp="+AppConfig.getTimeStamp(),callback,true);
    }

    /***
     * 查看当前微信号是否绑定手机号
     * @param context
     * @param wxNo 微信openID
     * @param callback
     */
    public static void isAlreadyBindPhone(Context context,String wxNo,BasicHttp.IMyCallBack callback){

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("wxloginid",wxNo);
//        RequestBody requestBodyPost=AppConfig.getBasicRequestBody(context).add("Args",jsonObject.toJSONString()).build();
        BasicHttp.getExec(context,Constants.server_domain+"user/LoginThirdParty?Args="+jsonObject.toJSONString()+"&Timestamp="+AppConfig.getTimeStamp(),callback,true);

    }


    public static void modifyPwd(Context context,String phoneNo,String password,String verifyCode,BasicHttp.IMyCallBack callback){

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("MobileNo",phoneNo);
        jsonObject.put("NewUserPwd",password);
        jsonObject.put("VerifyCode",verifyCode);

        RequestBody requestBodyPost=AppConfig.getBasicRequestBody(context).add("Args",jsonObject.toJSONString()).build();
        BasicHttp.postExec(context,Constants.server_domain+"user/resetpwd",requestBodyPost,callback);
    }


    public static void getOrderData(Context context,int vipId,BasicHttp.IMyCallBack callback){

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("AppUserId",vipId);

        BasicHttp.getExec(context,Constants.server_domain+"vip/MyCommonStatusList?Args="+jsonObject.toJSONString()+"&Timestamp="+AppConfig.getTimeStamp(),callback,false);
    }


    //脾气盒子
    public static void getPQHXData(Context context,int vipId,BasicHttp.IMyCallBack callback){

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("VipId",vipId);

        BasicHttp.getExec(context,Constants.server_domain+"Porduct/MyPackageLst?Args="+jsonObject.toJSONString()+"&Timestamp="+AppConfig.getTimeStamp(),callback,false);
    }


}
